4 * SQUID Web Proxy Cache http://www.squid-cache.org/
5 * ----------------------------------------------------------
7 * Squid is the result of efforts by numerous individuals from
8 * the Internet community; see the CONTRIBUTORS file for full
9 * details. Many organizations have provided support for Squid's
10 * development; see the SPONSORS file for full details. Squid is
11 * Copyrighted (C) 2001 by the Regents of the University of
12 * California; see the COPYRIGHT file for full details. Squid
13 * incorporates software developed and/or copyrighted by other
14 * sources; see the CREDITS file for full details.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 #ifndef SQUID_UFSCOMMON_H
32 #define SQUID_UFSCOMMON_H
35 #define DefaultLevelOneDirs 16
36 #define DefaultLevelTwoDirs 256
37 #define STORE_META_BUFSZ 4096
40 class ConfigOptionVector
;
47 class UFSSwapDir
: public SwapDir
51 static int IsUFSDir(SwapDir
* sd
);
52 static int DirClean(int swap_index
);
53 static int FilenoBelongsHere(int fn
, int F0
, int F1
, int F2
);
55 UFSSwapDir(char const *aType
, const char *aModuleType
);
57 virtual void create();
58 virtual void dump(StoreEntry
&) const;
60 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
61 virtual bool doubleCheck(StoreEntry
&);
62 virtual void unlink(StoreEntry
&);
63 virtual void statfs(StoreEntry
&)const;
64 virtual void maintain();
65 virtual int canStore(StoreEntry
const &)const;
66 virtual void reference(StoreEntry
&);
67 virtual void dereference(StoreEntry
&);
68 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
69 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
70 virtual void openLog();
71 virtual void closeLog();
72 virtual int writeCleanStart();
73 virtual void writeCleanDone();
74 virtual void logEntry(const StoreEntry
& e
, int op
) const;
75 virtual void parse(int index
, char *path
);
76 virtual void reconfigure(int, char *);
77 virtual int callback();
80 void unlinkFile(sfileno f
);
81 // move down when unlink is a virtual method
84 char *fullPath(sfileno
, char *) const;
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 StoreEntry
*addDiskRestore(const cache_key
* key
,
94 uint64_t swap_file_sz
,
102 int validFileno(sfileno filn
, int flag
) const;
103 int mapBitAllocate();
104 virtual ConfigOption
*getOptionTree() const;
108 bool validL2(int) const;
109 bool validL1(int) const;
111 void replacementAdd(StoreEntry
*e
);
112 void replacementRemove(StoreEntry
*e
);
121 void parseSizeL1L2();
122 static int NumberOfUFSDirs
;
123 static int * UFSDirToGlobalDirMapping
;
124 bool pathIsDirectory(const char *path
)const;
126 static EVH CleanEvent
;
127 bool verifyCacheDirs();
129 int createDirectory(const char *path
, int);
130 void createSwapSubDirs();
131 void dumpEntry(StoreEntry
&) const;
132 char *logFile(char const *ext
= NULL
)const;
133 void changeIO(DiskIOModule
*);
134 bool optionIOParse(char const *option
, const char *value
, int reconfiguring
);
135 void optionIODump(StoreEntry
* e
) const;
136 mutable ConfigOptionVector
*currentIOOptions
;
141 #include "RefCount.h"
142 #include "DiskIO/IORequestor.h"
145 * UFS dir specific IO calls
147 \todo This should be whittled away.
148 * DiskIOModule should be providing the entire needed API.
151 class DiskIOStrategy
;
160 UFSStrategy (DiskIOStrategy
*);
161 virtual ~UFSStrategy ();
162 /* Not implemented */
163 UFSStrategy (UFSStrategy
const &);
164 UFSStrategy
&operator=(UFSStrategy
const &);
166 virtual bool shedLoad();
170 StoreIOState::Pointer
createState(SwapDir
*SD
, StoreEntry
*e
, StoreIOState::STIOCB
* callback
, void *callback_data
) const;
172 virtual RefCount
<DiskFile
> newFile (char const *path
);
173 StoreIOState::Pointer
open(SwapDir
*, StoreEntry
*, StoreIOState::STFNCB
*,
174 StoreIOState::STIOCB
*, void *);
175 StoreIOState::Pointer
create(SwapDir
*, StoreEntry
*, StoreIOState::STFNCB
*,
176 StoreIOState::STIOCB
*, void *);
178 virtual void unlinkFile (char const *);
181 virtual int callback();
183 /** Init per-instance logic */
186 /** cachemgr output on the IO instance stats */
187 virtual void statfs(StoreEntry
& sentry
)const;
189 /** The io strategy in use */
193 friend class UFSSwapDir
;
196 /** Common ufs-store-dir logic */
201 class UFSStoreState
: public StoreIOState
, public IORequestor
205 void * operator new (size_t);
206 void operator delete (void *);
207 UFSStoreState(SwapDir
* SD
, StoreEntry
* anEntry
, STIOCB
* callback_
, void *callback_data_
);
209 virtual void close();
210 virtual void closeCompleted();
212 virtual void ioCompletedNotification();
213 virtual void readCompleted(const char *buf
, int len
, int errflag
, RefCount
<ReadRequest
>);
214 virtual void writeCompleted(int errflag
, size_t len
, RefCount
<WriteRequest
>);
215 RefCount
<DiskFile
> theFile
;
221 void read_(char *buf
, size_t size
, off_t offset
, STRCB
* callback
, void *callback_data
);
222 void write(char const *buf
, size_t size
, off_t offset
, FREE
* free_func
);
225 virtual void doCloseCallback (int errflag
);
231 MEMPROXY_CLASS(UFSStoreState::_queued_read
);
244 MEMPROXY_CLASS(UFSStoreState::_queued_write
);
252 /** \todo These should be in the IO strategy */
257 * the write_draining flag is used to avoid recursion inside
258 * the UFSStoreState::drainWriteQueue() method.
263 * The try_closing flag is set by UFSStoreState::tryClosing()
264 * when UFSStoreState wants to close the file, but cannot
265 * because of pending I/Os. If set, UFSStoreState will
266 * try to close again in the I/O callbacks.
270 link_list
*pending_reads
;
271 link_list
*pending_writes
;
272 void queueRead(char *, size_t, off_t
, STRCB
*, void *);
273 void queueWrite(char const *, size_t, off_t
, FREE
*);
274 bool kickReadQueue();
275 void drainWriteQueue();
280 CBDATA_CLASS(UFSStoreState
);
286 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read
);
287 MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write
);
290 #include "StoreSearch.h"
293 class StoreSearchUFS
: public StoreSearch
297 StoreSearchUFS(RefCount
<UFSSwapDir
> sd
);
298 StoreSearchUFS(StoreSearchUFS
const &);
299 virtual ~StoreSearchUFS();
301 /** \todo Iterator API - garh, wrong place */
303 * callback the client when a new StoreEntry is available
306 virtual void next(void (callback
)(void *cbdata
), void *cbdata
);
309 \retval true if a new StoreEntry is immediately available
310 \retval false if a new StoreEntry is NOT immediately available
314 virtual bool error() const;
315 virtual bool isDone() const;
316 virtual StoreEntry
*currentItem();
318 RefCount
<UFSSwapDir
> sd
;
319 RemovalPolicyWalker
*walker
;
322 CBDATA_CLASS2(StoreSearchUFS
);
323 /// \bug (callback) should be hidden behind a proper human readable name
324 void (callback
)(void *cbdata
);
326 StoreEntry
* current
;
331 class StoreSwapLogData
;
334 class UFSSwapLogParser
342 UFSSwapLogParser(FILE *fp
):log(fp
),log_entries(-1), record_size(0) {
344 virtual ~UFSSwapLogParser() {};
346 static UFSSwapLogParser
*GetUFSSwapLogParser(FILE *fp
);
348 virtual bool ReadRecord(StoreSwapLogData
&swapData
) = 0;
349 int SwapLogEntries();
360 class RebuildState
: public RefCountable
364 static EVH RebuildStep
;
366 RebuildState(RefCount
<UFSSwapDir
> sd
);
369 /** \todo Iterator API - garh, wrong place */
371 * callback the client when a new StoreEntry is available
374 virtual void next(void (callback
)(void *cbdata
), void *cbdata
);
377 \retval true if a new StoreEntry is immediately available
378 \retval false if a new StoreEntry is NOT immediately available
381 virtual bool error() const;
382 virtual bool isDone() const;
383 virtual StoreEntry
*currentItem();
385 RefCount
<UFSSwapDir
> sd
;
388 UFSSwapLogParser
*LogParser
;
394 unsigned int need_to_validate
:1;
395 unsigned int clean
:1;
402 struct dirent
*entry
;
404 char fullpath
[SQUID_MAXPATHLEN
];
405 char fullfilename
[SQUID_MAXPATHLEN
];
407 struct _store_rebuild_data counts
;
410 CBDATA_CLASS2(RebuildState
);
411 void rebuildFromDirectory();
412 void rebuildFromSwapLog();
414 int getNextFile(sfileno
*, int *size
);
415 StoreEntry
*currentEntry() const;
416 void currentEntry(StoreEntry
*);
420 /// \bug (callback) should be hidden behind a proper human readable name
421 void (callback
)(void *cbdata
);
426 #include "ufscommon.cci"
429 #endif /* SQUID_UFSCOMMON_H */