]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSSwapDir.h
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
29 #ifndef SQUID_FS_UFS_UFSSWAPDIR_H
30 #define SQUID_FS_UFS_UFSSWAPDIR_H
32 #include "SquidString.h"
34 #include "StoreIOState.h"
35 #include "StoreSearch.h"
36 #include "swap_log_op.h"
38 #include "UFSStrategy.h"
41 class ConfigOptionVector
;
50 class UFSSwapDir
: public SwapDir
53 static bool IsUFSDir(SwapDir
* sd
);
54 static int DirClean(int swap_index
);
55 /** check whether swapfile belongs to the specified cachedir/l1dir/l2dir
57 * \param cachedir the number of the cachedir which is being tested
58 * \param level1dir level-1 dir in the cachedir
59 * \param level2dir level-2 dir
61 static bool FilenoBelongsHere(int fn
, int cachedir
, int level1dir
, int level2dir
);
63 UFSSwapDir(char const *aType
, const char *aModuleType
);
64 /** Initial setup / end destruction */
66 /** Create a new SwapDir (-z command-line option) */
67 virtual void create();
68 virtual void dump(StoreEntry
&) const;
70 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
71 /** double-check swap during rebuild (-S command-line option)
73 * called by storeCleanup if needed
75 virtual bool doubleCheck(StoreEntry
&);
76 virtual bool unlinkdUseful() const;
77 /** unlink a file, and remove its entry from the filemap */
78 virtual void unlink(StoreEntry
&);
79 virtual void statfs(StoreEntry
&)const;
80 virtual void maintain();
81 /** check whether this filesystem can store the given object
83 * UFS filesystems will happily store anything as long as
84 * the LRU time isn't too small
86 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const;
87 /** reference an object
89 * This routine is called whenever an object is referenced, so we can
90 * maintain replacement information within the storage fs.
92 virtual void reference(StoreEntry
&);
93 /** de-reference an object
95 * This routine is called whenever the last reference to an object is
96 * removed, to maintain replacement information within the storage fs.
98 virtual bool dereference(StoreEntry
&, bool);
99 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
100 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
101 virtual void openLog();
102 virtual void closeLog();
103 virtual int writeCleanStart();
104 virtual void writeCleanDone();
105 virtual void logEntry(const StoreEntry
& e
, int op
) const;
106 virtual void parse(int index
, char *path
); ///parse configuration and setup new SwapDir
107 virtual void reconfigure(); ///reconfigure the SwapDir
108 virtual int callback();
110 virtual void swappedOut(const StoreEntry
&e
);
111 virtual uint64_t currentSize() const { return cur_size
; }
112 virtual uint64_t currentCount() const { return n_disk_objects
; }
114 void unlinkFile(sfileno f
);
115 // move down when unlink is a virtual method
117 Fs::Ufs::UFSStrategy
*IO
;
118 char *fullPath(sfileno
, char *) const;
120 void closeTmpSwapLog();
121 FILE *openTmpSwapLog(int *clean_flag
, int *zero_flag
);
122 char *swapSubDir(int subdirn
) const;
123 int mapBitTest(sfileno filn
);
124 void mapBitReset(sfileno filn
);
125 void mapBitSet(sfileno filn
);
126 /** Add a new object to the cache with empty memory copy and pointer to disk
128 * This method is used to rebuild a store from disk
130 StoreEntry
*addDiskRestore(const cache_key
* key
,
132 uint64_t swap_file_sz
,
140 /// Undo the effects of UFSSwapDir::addDiskRestore().
141 void undoAddDiskRestore(StoreEntry
*e
);
142 int validFileno(sfileno filn
, int flag
) const;
143 int mapBitAllocate();
144 virtual ConfigOption
*getOptionTree() const;
148 bool validL2(int) const;
149 bool validL1(int) const;
151 /** Add and remove the given StoreEntry from the replacement policy in use */
152 void replacementAdd(StoreEntry
*e
);
153 void replacementRemove(StoreEntry
*e
);
162 void parseSizeL1L2();
163 static int NumberOfUFSDirs
;
164 static int * UFSDirToGlobalDirMapping
;
165 bool pathIsDirectory(const char *path
)const;
167 static EVH CleanEvent
;
168 /** Verify that the the CacheDir exists
170 * If this returns < 0, then Squid exits, complains about swap
171 * directories not existing, and instructs the admin to run 'squid -z'
172 * Called by UFSSwapDir::init
174 bool verifyCacheDirs();
176 int createDirectory(const char *path
, int);
177 void createSwapSubDirs();
178 void dumpEntry(StoreEntry
&) const;
179 char *logFile(char const *ext
= NULL
)const;
180 void changeIO(DiskIOModule
*);
181 bool optionIOParse(char const *option
, const char *value
, int reconfiguring
);
182 void optionIODump(StoreEntry
* e
) const;
183 mutable ConfigOptionVector
*currentIOOptions
;
185 uint64_t cur_size
; ///< currently used space in the storage area
186 uint64_t n_disk_objects
; ///< total number of objects stored
191 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */